package com.zgjkhis.modules.system.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageInfo;
import com.zgjkhis.common.service.impl.BaseServiceImpl;
import com.zgjkhis.domain.PageResult;
import com.zgjkhis.exception.ServiceException;
import com.zgjkhis.modules.enums.DrugTypeEnum;
import com.zgjkhis.modules.security.security.LoginUserUtil;
import com.zgjkhis.modules.system.domain.Drug;
import com.zgjkhis.modules.system.domain.DrugDelivery;
import com.zgjkhis.modules.system.domain.DrugDeliveryDetail;
import com.zgjkhis.modules.system.domain.DrugWareHousingDetail;
import com.zgjkhis.modules.system.domain.vo.DrugDeliveryDetailVO;
import com.zgjkhis.modules.system.domain.vo.DrugDeliveryVo;
import com.zgjkhis.modules.system.service.DrugDeliveryDetailService;
import com.zgjkhis.modules.system.service.DrugDeliveryService;
import com.zgjkhis.modules.system.service.DrugService;
import com.zgjkhis.modules.system.service.DrugWareHousingDetailService;
import com.zgjkhis.modules.system.service.dto.DrugDeliveryQueryCriteria;
import com.zgjkhis.modules.system.service.dto.DrugQueryCriteria;
import com.zgjkhis.modules.system.service.dto.DrugWareHousingDetailDto;
import com.zgjkhis.modules.system.service.mapper.DrugDeliveryMapper;
import com.zgjkhis.modules.util.CharUtil;
import com.zgjkhis.utils.DateUtils;
import com.zgjkhis.utils.FileUtil;
import com.zgjkhis.utils.RandomUtils;
import com.zgjkhis.utils.SecurityUtils;
import lombok.AllArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.ParseException;
import java.util.*;

// 默认不使用缓存
//import org.springframework.cache.annotation.CacheConfig;
//import org.springframework.cache.annotation.CacheEvict;
//import org.springframework.cache.annotation.Cacheable;

/**
 * @Author yzq
 * @Description 药品入库
 * @Date 2021/6/23 9:47
 * @Param
 * @return
 **/
@Service
@AllArgsConstructor
//@CacheConfig(cacheNames = "user")
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class DrugDeliveryServiceImpl extends BaseServiceImpl<DrugDeliveryMapper, DrugDelivery> implements DrugDeliveryService {

    private final DrugService drugService;
    private final DrugDeliveryDetailService drugDeliveryDetailService;
    private final DrugWareHousingDetailService drugWareHousingDetailService;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean createDrugWareHousing(DrugDelivery drugDelivery) {
        if (drugDelivery.getStatus() == 2) {
            if (CharUtil.isEmpty(drugDelivery.getCollectDeptId()) || CharUtil.isEmpty(drugDelivery.getCollectUseId())) {
                throw new ServiceException("领用科室及领用人不能为空");
            }
        }
        DrugDelivery delivery = new DrugDelivery();
        String deliveryNo = DateUtils.dateTimeNow() + RandomUtils.getRandomNumbers(6);
        delivery.setId(drugDelivery.getId());
        if (!CharUtil.isEmpty(drugDelivery.getId())) {
            DrugDelivery temp = this.getById(drugDelivery.getId());
            if (CharUtil.isEmpty(temp) || temp.getStatus() == 2 || temp.getStatus() == 3) {
                throw new ServiceException("出库单子【" + drugDelivery.getId() + "】不存在,或状态不对");
            }
            deliveryNo = temp.getDeliveryNo();
        }
        delivery.setDeliveryNo(deliveryNo);
        delivery.setDeliveryType(drugDelivery.getDeliveryType());
        delivery.setCreateUserId(SecurityUtils.getUserId().toString());
        delivery.setCreateUserName(LoginUserUtil.getNickName());
        delivery.setStatus(drugDelivery.getStatus());
        if (drugDelivery.getStatus() == 2 || drugDelivery.getStatus() == 3) {
            delivery.setCheckUserId(SecurityUtils.getUserId().toString());
            delivery.setCheckUserName(LoginUserUtil.getNickName());
            delivery.setCheckTime(new Date());
        }
        delivery.setRemark(drugDelivery.getRemark());
        delivery.setPharmacyId(LoginUserUtil.getPharmId());
        delivery.setCollectDeptId(drugDelivery.getCollectDeptId());
        delivery.setCollectDeptName(drugDelivery.getCollectDeptName());
        delivery.setCollectUseId(drugDelivery.getCollectUseId());
        delivery.setCollectUseName(drugDelivery.getCollectUseName());
        List<DrugDeliveryDetail> list = new ArrayList<>();
        if (CharUtil.isEmpty(drugDelivery.getList())) {
            throw new ServiceException("入库清单没有药品");
        }
        delivery.setDeliveryQuantity(drugDelivery.getList().size());
        delivery.setDrugType(drugDelivery.getDrugType());
        drugDeliveryDetailService.remove(Wrappers.<DrugDeliveryDetail>query().lambda().eq(DrugDeliveryDetail::getDeliveryNo, deliveryNo));
        for (DrugDeliveryDetailVO drugDeliveryDetail : drugDelivery.getList()) {
            if (CharUtil.isEmpty(drugDeliveryDetail.getWarehousingDetailId())) {
                throw new ServiceException("请完善药品清单再出库(存在药品出库id为空的药品)");
            }
            if (CharUtil.isEmpty(drugDeliveryDetail.getUseUnit())) {
                throw new ServiceException("请完善药品清单再出库(存在药品出库单位为空的药品)");
            }
            DrugWareHousingDetail drugWareHousingDetail = drugWareHousingDetailService.getById(drugDeliveryDetail.getWarehousingDetailId());
            if (CharUtil.isEmpty(drugWareHousingDetail)) {
                throw new ServiceException("入库清单不存在");
            }
            DrugDeliveryDetail detail = new DrugDeliveryDetail();
            detail.setDrugId(drugWareHousingDetail.getDrugId());
            Drug drug = drugService.getOne(Wrappers.<Drug>query().lambda().eq(Drug::getId, drugWareHousingDetail.getDrugId()));
            if (CharUtil.isEmpty(drug)) {
                throw new ServiceException("药品Id(" + drugWareHousingDetail.getDrugId() + ")不存在");
            }
            detail.setDrugName(drug.getDrugName());
            if ((drugDeliveryDetail.getUseUnit().equals(drug.getPackageUnit()) && CharUtil.isEmpty(drugDeliveryDetail.getDeliveryNum())) ||
                    (drugDeliveryDetail.getUseUnit().equals(drug.getTotalDoseUnit()) && CharUtil.isEmpty(drugDeliveryDetail.getMinDeliveryNum()))) {
                throw new ServiceException("药品：【" + drug.getDrugName() + "】出库数量不能为空");
            }
            //药材为3中成药，4西药，5耗材 存在零售,以剂量单位计算
            if (DrugTypeEnum.ZCY.getCode().equals(drug.getDrugType()) ||
                    DrugTypeEnum.XY.getCode().equals(drug.getDrugType()) || DrugTypeEnum.OTHER.getCode().equals(drug.getDrugType()) ||
                    DrugTypeEnum.HC.getCode().equals(drug.getDrugType())) {
                if (!drugDeliveryDetail.getUseUnit().equals(drug.getPackageUnit()) && !drugDeliveryDetail.getUseUnit().equals(drug.getTotalDoseUnit())) {
                    throw new ServiceException("药品Id(" + drugWareHousingDetail.getDrugId() + ")出库单位错误");
                }
                if (drugDeliveryDetail.getUseUnit().equals(drug.getPackageUnit())) {
                    if (drugWareHousingDetail.getLeftCount() < drugDeliveryDetail.getDeliveryNum()) {
                        throw new ServiceException("药品：【" + drug.getDrugName() + "】库存不足");
                    }
                } else {
                    if ((drugWareHousingDetail.getLeftCount() * drug.getTotalDose() + drugWareHousingDetail.getMinLeftCount()) < drugDeliveryDetail.getMinDeliveryNum()) {
                        throw new ServiceException("药品：【" + drug.getDrugName() + "】库存不足");
                    }
                }
                detail.setPackageUnit(drug.getPackageUnit());
                detail.setDoseUnit(drug.getTotalDoseUnit());
            } else {
                if (!drugDeliveryDetail.getUseUnit().equals(drug.getPackageUnit())) {
                    throw new ServiceException("药品Id(" + drugWareHousingDetail.getDrugId() + ")出库单位错误");
                }
                if (drugWareHousingDetail.getLeftCount() < drugDeliveryDetail.getDeliveryNum()) {
                    throw new ServiceException("药品：【" + drug.getDrugName() + "】库存不足");
                }

                detail.setPackageUnit(drug.getPackageUnit());
                detail.setDoseUnit(drug.getDoseUnit());
            }
            if (drug.getPackageUnit().equals(drugDeliveryDetail.getUseUnit())) {
                detail.setDeliveryNum(drugDeliveryDetail.getDeliveryNum());
            } else {
                detail.setMinDeliveryNum(drugDeliveryDetail.getMinDeliveryNum());
            }
            detail.setUseUnit(drugDeliveryDetail.getUseUnit());
            detail.setCostPrice(drugWareHousingDetail.getCostPrice());
            detail.setTermOfValidity(drugWareHousingDetail.getTermOfValidity());
            detail.setBatchNo(drugWareHousingDetail.getBatchNo());
            detail.setStock(drugWareHousingDetail.getLeftCount());
            detail.setSalePrice(drugWareHousingDetail.getSalePrice());
            detail.setId(drugDeliveryDetail.getId());
            detail.setDeliveryNo(deliveryNo);
            detail.setDrugSpec(drug.getDrugSpec());
            detail.setDrugManufactor(drug.getDrugManufactor());

            detail.setPharmacyId(delivery.getPharmacyId());
            detail.setSelfPrice(drugDeliveryDetail.getSelfPrice());
            detail.setRedPun(drugDeliveryDetail.getRedPun());
            detail.setWarehousingDetailId(drugDeliveryDetail.getWarehousingDetailId());
            detail.setCoefficient(drugDeliveryDetail.getCoefficient());
            detail.setCoefficientName(drugDeliveryDetail.getCoefficientName());
            detail.setSupplyName(drugDeliveryDetail.getSupplyName());
            detail.setQuantity(drugDeliveryDetail.getQuantity());
            detail.setEquivalent(drugDeliveryDetail.getEquivalent());
            if (drugWareHousingDetail.getLeftCount() < drugDeliveryDetail.getDeliveryNum()) {
                throw new ServiceException("库存不足");
            }
            if (drugDelivery.getStatus() == 2) {
                //出库修改，入库清单数量
                DrugWareHousingDetail housingDetail = new DrugWareHousingDetail();
                housingDetail.setId(drugWareHousingDetail.getId());
                housingDetail.setLeftCount(drugWareHousingDetail.getLeftCount() - (CharUtil.isEmpty(drugDeliveryDetail.getDeliveryNum()) ? 0 : drugDeliveryDetail.getDeliveryNum()));
                //药材为3中成药，4西药，5耗材 存在零售,以剂量单位计算
                if ((DrugTypeEnum.ZCY.getCode().equals(drug.getDrugType()) ||
                        DrugTypeEnum.XY.getCode().equals(drug.getDrugType()) || DrugTypeEnum.OTHER.getCode().equals(drug.getDrugType()) ||
                        DrugTypeEnum.HC.getCode().equals(drug.getDrugType()))) {
                    if (!CharUtil.isEmpty(drugDeliveryDetail.getMinDeliveryNum()) && drugDeliveryDetail.getMinDeliveryNum() > 0) {
                        if (drugWareHousingDetail.getMinLeftCount() >= drugDeliveryDetail.getMinDeliveryNum()) {
                            housingDetail.setMinLeftCount(drugWareHousingDetail.getMinLeftCount() - drugDeliveryDetail.getMinDeliveryNum());
                        } else {
                            //扣除剩余的剂量单位剩余数，还有多少
                            int minDeliverNum = drugDeliveryDetail.getMinDeliveryNum() - drugWareHousingDetail.getMinLeftCount();
                            int ceil = (int) Math.ceil(Double.valueOf(minDeliverNum) / Double.valueOf(drug.getTotalDose()));
                            housingDetail.setLeftCount(housingDetail.getLeftCount() - ceil);
                            housingDetail.setMinLeftCount(ceil * drug.getTotalDose() - minDeliverNum);
                        }
                    }
                }
                drugWareHousingDetailService.updateById(housingDetail);

                //出库修改药品数量
//                drugService.updateStockByIdForDelivery(drug.getId());
                drugService.updateStockById(drug.getId());
                drugService.updateMothUseById(drug.getId(), drugDeliveryDetail.getDeliveryNum(), drugDeliveryDetail.getMinDeliveryNum());
            }
            list.add(detail);
        }
        this.saveOrUpdate(delivery);
        drugDeliveryDetailService.saveOrUpdateBatch(list);
        return true;
    }

    @Override
    public PageResult<DrugDelivery> findAllByPageable(DrugDeliveryQueryCriteria criteria, Pageable pageable) {
        getPage(pageable);
        PageInfo<DrugDelivery> page = new PageInfo<>(baseMapper.findAllByPageable(criteria));
        return PageResult.data(page);
    }

    @Override
    public void outTemplate(DrugQueryCriteria criteria, HttpServletResponse response) throws IOException {
        List<DrugWareHousingDetailDto> allList = drugWareHousingDetailService.findAllWareDetail(criteria);
        List<Map<String, Object>> list = new ArrayList<>();
        for (DrugWareHousingDetailDto detailDto : allList) {
            Map<String, Object> map = new LinkedHashMap<>();
            map.put("详情id", detailDto.getId());
            map.put("商品名称", detailDto.getDrugName());
            map.put("药品类型", DrugTypeEnum.findByCode(detailDto.getDrugType()));
            map.put("规格", detailDto.getDrugSpec());
            map.put("厂家", detailDto.getDrugManufactor());
            map.put("零售价", detailDto.getSalePrice());
            map.put("进货价", detailDto.getCostPrice());
            map.put("批次号", detailDto.getBatchNo());
            map.put("有效期", detailDto.getTermOfValidity());
            map.put("库存数量", detailDto.getLeftCount());
            map.put("出库数量", "");
            map.put("数量单位", detailDto.getPackageUnit());
            map.put("系数", detailDto.getCoefficient());
            map.put("出库总数量(不填则自动计算出库数量*系数)", "");
            list.add(map);
        }
        FileUtil.downloadExcel(list, response);
    }

    @Override
    public void inTemplate(MultipartFile file, Integer deliveryType, String collectDeptId, String collectUseId, String remark, String collectDeptName, String collectUseName, Integer drugType) throws IOException, ParseException {
        ExcelReader excelReader = ExcelUtil.getReader(file.getInputStream());
        DrugDelivery delivery = new DrugDelivery();
        String deliveryNo = DateUtils.dateTimeNow() + RandomUtils.getRandomNumbers(6);
        delivery.setDeliveryNo(deliveryNo);
        delivery.setDeliveryType(deliveryType);
        delivery.setCreateUserId(SecurityUtils.getUserId().toString());
        delivery.setCreateUserName(LoginUserUtil.getNickName());
        delivery.setStatus(1);
        delivery.setDrugType(drugType);
        if (!CharUtil.isEmpty(remark)) {
            delivery.setRemark(remark);
        }
        if (!CharUtil.isEmpty(collectDeptId)) {
            delivery.setCollectDeptId(collectDeptId);
            delivery.setCollectDeptName(collectDeptName);
        }
        if (!CharUtil.isEmpty(collectUseId)) {
            delivery.setCollectUseId(collectUseId);
            delivery.setCollectUseName(collectUseName);
        }
        delivery.setPharmacyId(LoginUserUtil.getPharmId());

        List<DrugDeliveryDetail> list = new ArrayList<>();
        List<List<Object>> listAll = excelReader.read();

        for (int i = 1; i < listAll.size(); i++) {
            DrugDeliveryDetail temp = new DrugDeliveryDetail();
            List<Object> rowlist = listAll.get(i);
            temp = saveByFlag1(rowlist, delivery);
            if (!CharUtil.isEmpty(temp)) {
                list.add(temp);
            }
        }
        if (list.size() == 0) {
            throw new ServiceException("请添加出库药品或填写出库数量");
        }
        delivery.setDeliveryQuantity(list.size());
        drugDeliveryDetailService.saveBatch(list);
        this.saveOrUpdate(delivery);

    }

    private DrugDeliveryDetail saveByFlag1(List<Object> rowlist, DrugDelivery delivery) throws ParseException {

        DrugDeliveryDetail detail = new DrugDeliveryDetail();
        String id = CharUtil.isEmpty(rowlist.get(0)) ? "" : rowlist.get(0).toString();
        String drugName = CharUtil.isEmpty(rowlist.get(1)) ? "" : rowlist.get(1).toString();
        String drugSpec = CharUtil.isEmpty(rowlist.get(3)) ? "" : rowlist.get(3).toString();
        String drugManufactor = CharUtil.isEmpty(rowlist.get(4)) ? "" : rowlist.get(4).toString();
        String salePrice = CharUtil.isEmpty(rowlist.get(5)) ? "" : rowlist.get(5).toString();
        String costPrice = CharUtil.isEmpty(rowlist.get(6)) ? "" : rowlist.get(6).toString();
        String batchNo = CharUtil.isEmpty(rowlist.get(7)) ? "" : rowlist.get(7).toString();
        String termOfValidity = CharUtil.isEmpty(rowlist.get(8)) ? "" : rowlist.get(8).toString();
        String leftCount = CharUtil.isEmpty(rowlist.get(9)) ? "" : rowlist.get(9).toString();
        String deliveryNum1 = CharUtil.isEmpty(rowlist.get(10)) ? "" : rowlist.get(10).toString();
        String packageUnit = CharUtil.isEmpty(rowlist.get(11)) ? "" : rowlist.get(11).toString();
        String coefficient = CharUtil.isEmpty(rowlist.get(12)) ? "" : rowlist.get(12).toString();
        String deliveryNum2 = CharUtil.isEmpty(rowlist.get(13)) ? "" : rowlist.get(13).toString();

        if (!CharUtil.isEmpty(deliveryNum1) || !CharUtil.isEmpty(deliveryNum2)) {
            Integer deliveryNum;
            if (!CharUtil.isEmpty(deliveryNum2)) {
                deliveryNum = Integer.valueOf(deliveryNum2);
            } else {
                deliveryNum = (int) (Integer.valueOf(deliveryNum1) * Double.valueOf(coefficient));
            }
            DrugWareHousingDetail drugWareHousingDetail = drugWareHousingDetailService.getById(id);
            if (CharUtil.isEmpty(drugWareHousingDetail)) {
                throw new ServiceException("入库清单不存在");
            }
            detail.setDrugId(drugWareHousingDetail.getDrugId());
            Drug drug = drugService.getOne(Wrappers.<Drug>query().lambda().eq(Drug::getId, drugWareHousingDetail.getDrugId()));
            if (CharUtil.isEmpty(drug)) {
                throw new ServiceException("药品Id(" + drugWareHousingDetail.getDrugId() + ")不存在");
            }
            detail.setDrugName(drug.getDrugName());

            //药材为3中成药，4西药，5耗材 存在零售,以剂量单位计算
            if (DrugTypeEnum.ZCY.getCode().equals(drug.getDrugType()) ||
                    DrugTypeEnum.XY.getCode().equals(drug.getDrugType()) || DrugTypeEnum.OTHER.getCode().equals(drug.getDrugType()) ||
                    DrugTypeEnum.HC.getCode().equals(drug.getDrugType())) {
                if (!packageUnit.equals(drug.getPackageUnit()) && !packageUnit.equals(drug.getTotalDoseUnit())) {
                    throw new ServiceException("药品Id(" + drugWareHousingDetail.getDrugId() + ")出库单位错误");
                }
                if (packageUnit.equals(drug.getPackageUnit())) {
                    if (drugWareHousingDetail.getLeftCount() < deliveryNum) {
                        throw new ServiceException("药品：【" + drug.getDrugName() + "】库存不足");
                    }
                } else {
//                if((drugWareHousingDetail.getLeftCount()*drug.getTotalDose()+drugWareHousingDetail.getMinLeftCount())< drugDeliveryDetail.getMinDeliveryNum()){
//                    throw new ServiceException("药品：【"+drug.getDrugName()+"】库存不足");
//                }
                }
                detail.setPackageUnit(drug.getPackageUnit());
                detail.setDoseUnit(drug.getTotalDoseUnit());
            } else {
                if (!packageUnit.equals(drug.getPackageUnit())) {
                    throw new ServiceException("药品Id(" + drugWareHousingDetail.getDrugId() + ")出库单位错误");
                }
                if (drugWareHousingDetail.getLeftCount() < deliveryNum) {
                    throw new ServiceException("药品：【" + drug.getDrugName() + "】库存不足");
                }

                detail.setPackageUnit(drug.getPackageUnit());
                detail.setDoseUnit(drug.getDoseUnit());
            }
            if (drug.getPackageUnit().equals(packageUnit)) {
                detail.setDeliveryNum(deliveryNum);
            } else {
                detail.setMinDeliveryNum(0);
            }
            detail.setUseUnit(packageUnit);
            detail.setCostPrice(drugWareHousingDetail.getCostPrice());
            detail.setTermOfValidity(drugWareHousingDetail.getTermOfValidity());
            detail.setBatchNo(drugWareHousingDetail.getBatchNo());
            detail.setStock(drugWareHousingDetail.getLeftCount());
            detail.setSalePrice(drugWareHousingDetail.getSalePrice());
//        detail.setId(drugDeliveryDetail.getId());
            detail.setDeliveryNo(delivery.getDeliveryNo());
            detail.setDrugSpec(drug.getDrugSpec());
            detail.setDrugManufactor(drug.getDrugManufactor());

            detail.setPharmacyId(delivery.getPharmacyId());
            detail.setSelfPrice(drugWareHousingDetail.getSelfPrice());
            detail.setRedPun(drugWareHousingDetail.getRedPun());
            detail.setWarehousingDetailId(id);
            detail.setDrugManufactor(drugManufactor);
            detail.setSupplyName(drugManufactor);
            detail.setEquivalent(drugWareHousingDetail.getEquivalent());
            detail.setCoefficientName(drugWareHousingDetail.getCoefficientName());
            detail.setCoefficient(drugWareHousingDetail.getCoefficient());
            if (CharUtil.isEmpty(deliveryNum1)) {
                detail.setQuantity(0);
            } else {
                detail.setQuantity(Integer.valueOf(deliveryNum1));
            }
            if (drugWareHousingDetail.getLeftCount() < deliveryNum) {
                throw new ServiceException("库存不足");
            }
            return detail;
        } else {
            return null;
        }
    }


    @Override
    public void outDelivery(String id, HttpServletResponse response) throws IOException {
        //    List<Drug> allList = drugMapper.selectList(QueryHelpPlus.getPredicate(Drug.class, criteria));
        // List<Drug> allList = drugService.findAllByPageable(QueryHelpPlus.getPredicate(Drug.class, criteria));
        DrugDelivery drugDelivery = this.getById(id);
        DrugDeliveryVo drugDeliveryVo = new DrugDeliveryVo();
        BeanUtil.copyProperties(drugDelivery, drugDeliveryVo);
        List<DrugDeliveryDetailVO> detailVOS = drugDeliveryDetailService.queryList(drugDeliveryVo.getDeliveryNo());
        drugDeliveryVo.setList(detailVOS);

        List<Map<String, Object>> list = new ArrayList<>();
        for (DrugDeliveryDetailVO detailVO : detailVOS) {
            Map<String, Object> map = new LinkedHashMap<>();
            String type = "";
            switch (Integer.valueOf(detailVO.getDrugType())) {
                case 1:
                    type = "中药饮片";
                    break;
                case 2:
                    type = "配方颗粒";
                    map.put("红冲", detailVO.getRedPun());
                    map.put("成本价", detailVO.getSelfPrice());
                    break;
                case 3:
                    type = "中成药";
                    break;
                case 4:
                    type = "西药";
                    break;
                case 5:
                    type = "耗材";
                    break;
                case 6:
                    type = "敷贴粉剂";
                    break;
                default:
                    type = "未知";
                    break;
            }
            map.put("商品名称", detailVO.getDrugName());
            map.put("供应商", detailVO.getCoefficientName());
            map.put("进货价", detailVO.getCostPrice());
            map.put("批次号", detailVO.getBatchNo());
            map.put("有效期", detailVO.getTermOfValidity());
            map.put("库存数量", detailVO.getStock());
            map.put("包装规格", detailVO.getCoefficientName());
            map.put("换算系数", detailVO.getCoefficient());
            map.put("出库数量", detailVO.getQuantity());
            map.put("出库总数量", detailVO.getDeliveryNum());

            list.add(map);
        }
        FileUtil.downloadExcel(list, response);
    }

}
